{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f135f0dc-4874-40c8-97b5-8d2b16607711",
   "metadata": {},
   "source": [
    "# Preparing tables for analysis"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2aacf6b1-778a-46b5-ae8a-dbecc39d5dac",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "236a8334-c4f0-4ba1-b842-93483f0837cb",
   "metadata": {},
   "outputs": [],
   "source": [
    "controls = pd.read_csv(\"results/controls.csv\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "44b5a1a8-e3b8-4844-92a2-8ffb6222724a",
   "metadata": {},
   "source": [
    "## Certainty"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "591f86d1-b265-45e0-ae7f-6609afe5eb67",
   "metadata": {},
   "outputs": [],
   "source": [
    "certainty = pd.read_csv(\"results/certainty.csv\") \n",
    "merged = controls.merge(\n",
    "    certainty,\n",
    "    on=[\"id\", \"type\"],\n",
    "    how=\"inner\"\n",
    ")\n",
    "\n",
    "merged = merged.rename(columns={\n",
    "    \"id\": \"tweet.id\",\n",
    "    \"type\": \"type\",\n",
    "    \"certain\": \"is.certain\",\n",
    "    \"following_count\": \"account.follower.count\",\n",
    "    \"tweet_count\": \"account.tweet.count\",\n",
    "    \"len\": \"tweet.length\",\n",
    "})\n",
    "\n",
    "final = merged[\n",
    "    [\n",
    "        \"tweet.id\",\n",
    "        \"type\",\n",
    "        \"is.certain\",\n",
    "        \"account.follower.count\",\n",
    "        \"account.tweet.count\",\n",
    "        \"tweet.length\",\n",
    "    ]\n",
    "]\n",
    "\n",
    "final.to_csv(\"certainty_analysis.csv\", index=False)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "196dc2ed-2543-43fe-8748-d6b82880e4a8",
   "metadata": {},
   "source": [
    "## Causal Claims"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fd836d58-9e7f-4ba0-ac0b-fcb86de66db9",
   "metadata": {},
   "outputs": [],
   "source": [
    "causal = pd.read_csv(\"results/causal.csv\") \n",
    "merged = controls.merge(\n",
    "    causal,\n",
    "    on=[\"id\", \"type\"],\n",
    "    how=\"inner\"\n",
    ")\n",
    "\n",
    "merged = merged.rename(columns={\n",
    "    \"id\": \"tweet.id\",\n",
    "    \"type\": \"type\",\n",
    "    \"causal\": \"is.causal\",\n",
    "    \"following_count\": \"account.follower.count\",\n",
    "    \"tweet_count\": \"account.tweet.count\",\n",
    "    \"len\": \"tweet.length\",\n",
    "})\n",
    "\n",
    "final = merged[\n",
    "    [\n",
    "        \"tweet.id\",\n",
    "        \"type\",\n",
    "        \"is.causal\",\n",
    "        \"account.follower.count\",\n",
    "        \"account.tweet.count\",\n",
    "        \"tweet.length\",\n",
    "    ]\n",
    "]\n",
    "\n",
    "final.to_csv(\"causal_claims_analysis.csv\", index=False)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7f61a714-5d0c-485c-83b9-26d4e18f3866",
   "metadata": {},
   "source": [
    "## Authority figures"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dde18727-15ed-4a42-88a4-d6ab7172df3e",
   "metadata": {},
   "outputs": [],
   "source": [
    "figures = pd.read_csv(\"results/authority_figures.csv\") \n",
    "merged = controls.merge(\n",
    "    figures,\n",
    "    on=[\"id\", \"type\"],\n",
    "    how=\"inner\"\n",
    ")\n",
    "\n",
    "merged = merged.rename(columns={\n",
    "    \"id\": \"tweet.id\",\n",
    "    \"type\": \"type\",\n",
    "    \"researcher\": \"mentioned.researcher\",\n",
    "    \"politician\": \"mentioned.politician\",\n",
    "    \"physician\": \"mentioned.physician\",\n",
    "    \"following_count\": \"account.follower.count\",\n",
    "    \"tweet_count\": \"account.tweet.count\",\n",
    "    \"len\": \"tweet.length\",\n",
    "})\n",
    "\n",
    "final = merged[\n",
    "    [\n",
    "        \"tweet.id\",\n",
    "        \"type\",\n",
    "        \"mentioned.researcher\",\n",
    "        \"mentioned.politician\",\n",
    "        \"mentioned.physician\",\n",
    "        \"account.follower.count\",\n",
    "        \"account.tweet.count\",\n",
    "        \"tweet.length\",\n",
    "    ]\n",
    "]\n",
    "\n",
    "final.to_csv(\"authority_analysis.csv\", index=False)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:base] *",
   "language": "python",
   "name": "conda-base-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
